/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz;

import negocio.Fecha;
import negocio.Usuario;

/**
 *
 * @author pablo
 */
public class interfazLogueo extends javax.swing.JInternalFrame {
    Usuario user= new Usuario();
    Fecha fecha = new Fecha();
    Validacion valida = new Validacion();
    menu m;
    public interfazLogueo(menu m) {
        initComponents();
        this.m=m;
    }
 public void obtenervalores() {
        Usuario aux=null;
        Fecha auxfecha=null;
        String nombre="";
        String password="";
        char[] caracteres = jXLoginPane1.getPassword();
        nombre = jXLoginPane1.getUserName();
        for (int i = 0; i < caracteres.length; i++) {
            password = password  + caracteres[i];
        }
        aux = user.buscar2(nombre, password );
        if (aux != null) {
            auxfecha=fecha.buscar(nombre);
            if(auxfecha==null){
            fecha.setNombre(nombre);
            fecha.grabar();
             m.cargarUsuario(nombre,auxfecha.getFecha1(),password);     
            }else{
               fecha.setNombre(nombre); 
               fecha.modificar();
               m.cargarUsuario(nombre,auxfecha.getFecha1(),password);
               m.bloquar(true);
            }
           
            this.dispose();
        } else {
            valida.mensaje("No se ah Encontrado Intete de nuevo", 2);
            jXLoginPane1.setUserName("");  
        }
    }
    public void iniciarTiempo(){
        
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXLoginPane1 = new org.jdesktop.swingx.JXLoginPane();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/cancel.png"))); // NOI18N
        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/accept.png"))); // NOI18N
        jButton2.setText("Aceptar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jXLoginPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jXLoginPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.obtenervalores();
    }//GEN-LAST:event_jButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private org.jdesktop.swingx.JXLoginPane jXLoginPane1;
    // End of variables declaration//GEN-END:variables
}
